import unittest
from kea2 import precondition, prob
from hypium import BY, UiDriver

class RedNote(unittest.TestCase):
    d: "UiDriver"

    @classmethod
    def setUpClass(cls):
        cls.d = UiDriver.connect(
            device_sn="33Z0224620051970",
            connector="hdc"
        )

    @prob(0.8)
    @precondition(
        lambda self: (
            self.d.find_component(BY.id("rich_editor_social_use")) and
            len(self.d.find_component(BY.id("rich_editor_social_use")).getText()) > 0
        )
    )
    def test_send_button_should_exist_when_inputbox_has_text(self):
        assert self.d.find_component(BY.text("发送"))

    @prob(0.8)
    @precondition(
        lambda self: (
            self.d.find_component(BY.type("RichEditor")) and
            len(self.d.find_component(BY.type("RichEditor")).getText() == 0)
        )
    )
    def test_input_text(self):
        import uuid
        input_text = str(uuid.uuid4())
        self.d.input_text(BY.type("RichEditor"),input_text)
        assert self.d.find_component(BY.text(input_text))


if __name__ == "__main__":
    d = UiDriver.connect(
        device_sn = "23E0224307001843",
        connector="hdc"
    )


